package com.qqtech.qquan.community.dao;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.qqtech.core.common.util.BeanUtil;
import com.qqtech.core.frame.dao.BaseDaoImpl;
import com.qqtech.qquan.community.model.CommunityBase;
import com.qqtech.qquan.community.model.CommunityBaseQuery;
import com.qqtech.qquan.community.model.CommunityBaseVo;

@Repository
public class CommunityBaseDaoImpl extends BaseDaoImpl<CommunityBase> implements CommunityBaseDao {
	public static final Logger log = LoggerFactory.getLogger(CommunityBaseDaoImpl.class);

	@Override
	public Page<CommunityBaseVo> queryDistancePage(CommunityBaseQuery query, Pageable pageable) {
		List<CommunityBaseVo> contentList = this.sqlSessionTemplate.selectList(getSqlName("selectDistance"),
				getParams(query, pageable));
		return new PageImpl<CommunityBaseVo>(contentList, pageable, queryDistanceCount(query));
	}

	public int queryDistanceCount(CommunityBaseQuery query) {
		return ((Integer) this.sqlSessionTemplate.selectOne(getSqlName("selectDistanceCount"), BeanUtil.toMap(query)))
				.intValue();
	}

	@Override
	public List<CommunityBaseVo> queryDistanceList(CommunityBaseQuery query, Pageable pageable) {
		return this.sqlSessionTemplate.selectList(getSqlName("selectDistance"), getParams(query, pageable));
	}
}
